package com.ynunicom.dc.dingdingcontractapp.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ynunicom.dc.dingdingcontractapp.entity.requestbodyentity.PageRequestEntity;
import com.ynunicom.dc.dingdingcontractapp.entity.requestbodyentity.TransBody;
import com.ynunicom.dc.dingdingcontractapp.service.CompanyOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: jinye.Bai
 * @date: 2020/5/26 15:14
 */
@Service
@Slf4j
public class CompanyOptionServiceImpl implements CompanyOptionService {

    @Resource
    RestTemplate restTemplate;

    private static final String COMP_STAFFCOUNT_URL = "https://oapi.dingtalk.com/user/get_org_user_count?access_token={access_token}&onlyActive={onlyActive}";

    private static final String COMP_UNLOGINSTAFF_LIST_URL = "https://oapi.dingtalk.com/topapi/inactive/user/get?access_token={access_token}";

    @Override
    public JSONObject getStaffCount(TransBody<String> transBody) {
        Map<String,String> urlVar = new HashMap<>(2);
        urlVar.put("access_token",transBody.getAccess_token());
        urlVar.put("onlyActive",transBody.getRequestBody());
        return restTemplate.getForObject(COMP_STAFFCOUNT_URL,JSONObject.class,urlVar);
    }

    @Override
    public JSONObject getUnloginStaffList(TransBody<PageRequestEntity> transBody) {
        Map<String,String> urlVar = new HashMap<>(1);
        urlVar.put("access_token",transBody.getAccess_token());
        JSONObject sender = new JSONObject();
        sender.put("query_date",transBody.getRequestBody().getQuery_date());
        sender.put("offset",transBody.getRequestBody().getOffset());
        sender.put("size",transBody.getRequestBody().getSize());
        return restTemplate.postForObject(COMP_UNLOGINSTAFF_LIST_URL,sender,JSONObject.class,urlVar);
    }


}
